package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * ClassName: CategoryController
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2024/5/19 17:33
 * Version 1.0
 */
@RestController
@RequestMapping(value = "/admin/product/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    //分类列表 每次查询一层数据
    @GetMapping("/findCategoryList/{id}")
    public Result findCategoryList(@PathVariable("id") Long id){
        List<Category> list =  categoryService.findCategoryList(id);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    //数据导出
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }

    //数据导入（上传）
    @PostMapping("importData")
    public Result importData(MultipartFile file){
        //获取上传的文件
        categoryService.importData(file);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}
